import random

import time

import pymysql
import requests


def pay(uid, token):
    body = {
        'amount': '{}'.format(random.randint(9, 12) + round(random.random(), 2)),
        'driver_id': '{}'.format(uid),
        'shop_id': '{}'.format(uid),
        'provider': 'weixin',
        'access_token': '{}'.format(token)

    }
    CreateFarePaySign = requests.post('http://wangwang.hhbgrd.com/Pay/CreateFarePaySign', body)
    print(CreateFarePaySign.text)
    pass


def exec_sql(sql):
    conf = {
        'host': '192.168.16.18',
        'port': 6006,
        'user': 'dev',
        'password': 'jmdevcd',
        'db': 'growth_unmanned_shelves',
        'charset': 'utf8'
    }
    # sql2 = "update `growth_unmanned_shelves`.`meidian_order` set uid ='2000148210' where uid ='2000148211';" # 我的uid  2000148211  2000150056
    # sql3 = "update red_envelope SET uid = '34003' WHERE uid = '34002'"

    conn = pymysql.connect(**conf)
    print('mysql连接成功')
    cur = conn.cursor()
    cur.execute(sql)
    all = cur.fetchall()
    conn.commit()
    # 关闭游标
    cur.close()

    return all


if __name__ == '__main__':
    # sql = 'select qr_uuid from meidian_qr ORDER BY id desc limit 29;'
    # all = exec_sql(sql)
    # print(all)
    # for i in all:
    #     j = random.randint(1, 5)
    #     while j > 0:
    #         pay(i[0])
    #         j -= 1

    # 新客的token
    token_new = 'eyJleHAiOjE1MzMzNzY2NzgsImtpZCI6MH0.eyJ1aWQiOiIyMDAwMTQ4MjExIn0.80-ANsW9YthhOm0MrmvIKa2phURQizYimbE_YW__-Tc'
    # 老客的token
    token_old = 'eyJleHAiOjE1MzMzNzY3MTcsImtpZCI6Mn0.eyJ1aWQiOiIyMDAwMTUwMDU2In0.w9sclC_QZCmGovDzMa315f9EpyG_u4Iv_1Ue85eLIcE'
    # all = [34010,52042,34002]
    # for i in all:
    #     times = random.randint(1, 5)
    #     while times > 0:
    #         new_or_old = random.sample([token_new, token_old], 1)[0]
    #         pay(i, new_or_old)
    #         times -= 1
    # pay(34010,token_new)
    # pay(34002, token_new)
    pay(34002, token_new)
    #pay(52042, token_new)

